<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-30">
			<view class="margin-30-0 flex-around" @click="$tools.navigateBack()">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">会员积分</view>
				<view style="width: 40rpx;"></view>
			</view>
			<view class="integral-image-view">
				<image class="integral-image" src="https://wudang.chunchuangkeji.cn/image/19.png" mode=""></image>
				<view class="fontSize-15 color-704234 title1">我的积分</view>
				<view class="fontSize-30 color-704234 fontWeight-bold title2">{{userinfo.score}}</view>
				<view class="title3" @click="buyShow = true">
					<u-icon name="error-circle" color="#704234" size="20"></u-icon>
				</view>
			</view>
			<view class="padding-30-0 fontSize-18 color-704234">
				积分明细
			</view>

			<view class="bg-fff border-radius20 padding-30">
				<view class="flex-between f-divider1 padding-bottom30 margin-bottom30" v-for="(item,index) in list" :key="index">
					<view>
						<view class="fontSize-15 color-000 margin-bottom20">{{item.title}}</view>
						<view class="fontSize-13 color-999">{{item.createtime}}</view>
					</view>
					<view class="fontSize-20 color-000">{{item.num}}</view>
				</view>
			</view>
			
			<u-empty v-if="list.length == 0"
			        mode="list"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
					width="150px"
					height="150px"
					text="列表为空"
					textSize="18"
			>
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>

		<!-- 购买弹窗 -->
		<u-popup :show="buyShow" mode="center" bgColor="#F6F3E8" round="20">
			<view class="flex-justAliCenter-column popup-view">
				<view class="fontSize-18 fontWeight-bold color-704234">课程详情</view>
				<view class="buy-center">
					<!-- <image class="buy-center-image" src="" mode=""></image> -->
					<view class="buy-center-view1">
						<view class="padding-20 fontSize-15 color-704234">
							<u-parse :content="interText"></u-parse>
						</view>
					</view>
				</view> 
				<view class="buy-btn flex-center fontSize-15 color-704234 margin-top50" @click="buyShow = false">我知道了</view>
				<!-- <view class="fontSize-15 color-704234 margin-top30 text-center">暂不购买</view> -->
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buyShow: false,
				interText:'',
				userinfo:{},
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
			}
		},
		onLoad() {
			if (uni.getStorageSync('token')) {
				this.getData()
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getScoreList()
			this.getinterText()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getScoreList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getScoreList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			// 获取个人信息
			getData() {
				this.$http.post(this.$api.user_info, {}, {
					token: true
				}).then(res => {
					if (res.code === 1) {
						this.userinfo = res.data
					}
				})
			},
			// 积分规则
			async getinterText(){
				let res = await this.$http.post(this.$api.score_rule,{},{token:true})
				console.log(res)
				this.interText = res.data
			},
			 // 积分列表
		    async getScoreList(){
				this.$http.post(this.$api.score_list,{
					page:this.page,
					limit:this.limit
				},{token:true}).then(res => {
					this.list = [...this.list,...res.data]
				}).finally(() => {
					// 停止当前页面下拉刷新
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.buy-btn{
		width: 100%;
		height: 90rpx;
		background: linear-gradient( 130deg, #E2BF94 0%, #E5C6A0 28%, #E6CDB1 56%, #D1AA79 100%);
	}
	.buy-center-view1{
		width: 380rpx;
		// height: 220rpx;
		background-color: #EFDFCD;
		border-radius: 20rpx;
		padding: 30rpx;
	}
	.buy-center{
		// position: relative;
		margin: 30rpx 0;
		width:500rpx;
		// height: 260rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	// .buy-center-image{
	// 	width: 100%;
	// 	height: 100%;
	// 	flex-shrink: 0;
	// }
	.popup-view {
		padding: 30rpx;
		width: 500rpx;
		background-color: #F6F3E8;
	}
	.title3 {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	}

	.title2 {
		position: absolute;
		top: 90rpx;
		left: 30rpx;
	}

	.title1 {
		position: absolute;
		top: 30rpx;
		left: 30rpx;
	}

	.integral-image {
		width: 100%;
		height: 100%;
	}

	.integral-image-view {
		position: relative;
		width: 100%;
		height: 220rpx;
		margin-top: 50rpx;
	}

	.header-bg-image {
		width: 100%;
		min-height: 100vh;
	}
</style>